package cn.com.xy.sms.sdk.ui.popu.part;

import java.util.Map;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.com.xy.sms.sdk.Iservice.XyCallBack;
import cn.com.xy.sms.sdk.smsmessage.BusinessSmsMessage;
import cn.com.xy.sms.sdk.ui.R;
import cn.com.xy.sms.sdk.ui.popu.util.ChannelContentUtil;
import cn.com.xy.sms.sdk.ui.popu.util.ContentUtil;
import cn.com.xy.sms.sdk.ui.popu.util.ThemeUtil;
import cn.com.xy.sms.sdk.ui.popu.util.ViewUtil;
import cn.com.xy.sms.sdk.util.StringUtils;
import cn.com.xy.sms.util.ParseManager;

public class BubbleHintTextBody extends UIPart {

    private TextView mHintTv;
    private static final String HAS_BOTTOM = "hasBottom";

    public BubbleHintTextBody(Activity context, BusinessSmsMessage message, XyCallBack callback, int layoutId,
            ViewGroup root, int partId) {
        super(context, message, callback, layoutId, root, partId);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void initUi() throws Exception {
        // TODO Auto-generated method stub
        super.initUi();

        mHintTv = (TextView) mView.findViewById(R.id.duoqu_bubble_hint_text);
    }

    @Override
    public void setContent(BusinessSmsMessage message, boolean isRebind) throws Exception {
        // TODO Auto-generated method stub
        super.setContent(message, isRebind);
        if (message == null) {
            return;
        }
        String hintText = (String) message.getValue("m_by_original");
        if (StringUtils.isNull(hintText)) {
            mView.setVisibility(View.GONE);
            return;
        }else{
            mView.setVisibility(View.VISIBLE);
        }
        /* SMARTISAN-271 zhaoxiachao 20161202 start */
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mHintTv.getLayoutParams();
        /* SMARTISAN-271 zhaoxiachao 20161202 end */
        Boolean hasBottom = (Boolean) mMessage.getValue("hasBottom");
        if(hasBottom == null){
            hasBottom = ChannelContentUtil.hasBottomBotton(message);
            mMessage.putValue(HAS_BOTTOM, hasBottom);
            ParseManager.updateMatchCacheManager(mMessage);
        }else{
            hasBottom = (Boolean) mMessage.getValue(HAS_BOTTOM);
        }
        
        if(ChannelContentUtil.hasBottomBotton(message)){
            params.bottomMargin = ViewUtil.dp2px(mContext, 15);
        }else{
            params.bottomMargin = ViewUtil.dp2px(mContext, 8);
        }
        mHintTv.setLayoutParams(params);
        
        setViewStyle(message);
        ContentUtil.setText(mHintTv, hintText, "");
    }

    @SuppressLint("ResourceAsColor")
    private void setViewStyle(BusinessSmsMessage message) {
        ThemeUtil.setViewBg(mContext, mView, "", R.drawable.duoqu_v_by_bg_1);
        ThemeUtil.setTextColor(mContext, mHintTv, (String) message.getValue("v_by_original"), R.color.duoqu_theme_color_5010);
    }

    @Override
    public void changeData(Map<String, Object> param) {
        /* SMARTISAN-261 zhaoxiachao 20161129 start */
        if(param != null && !StringUtils.isNull(param.get(ChannelContentUtil.CHANGE_TRAIN)+"")){
            return;
        }
        /* SMARTISAN-261 zhaoxiachao 20161129 end */
    }
}

